//
//  AppDelegate.swift
//  18.3 tabbar
//
//  Created by 李煜 on 2024/6/26.
//

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        window?.backgroundColor = .white
        
        let tabBarViewController = UITabBarController()
        let vc1 = FirstVC()
        vc1.tabBarItem.title = "首页"
        //选染色必须前提是.alwaysOriginal
        vc1.tabBarItem.image = UIImage(named: "home")//?.withRenderingMode(.alwaysOriginal)
        vc1.tabBarItem.selectedImage = UIImage(named: "home")
        
        let vc2 = SecondVC()
        vc2.title = "兴趣"
        vc2.tabBarItem.image = UIImage(named: "favorite")
        //设置badge
        vc2.tabBarItem.badgeValue = "99+"
        vc2.tabBarItem.badgeColor = .purple
        vc2.tabBarItem.setBadgeTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.cyan], for: .normal)
        
        let vc3 = ThirdVC()
        vc3.title = "我"
        vc3.tabBarItem.image = UIImage(named: "me")
        
        let vc4 = FourthVC()
        vc4.title = "通知"
        vc4.tabBarItem.image = UIImage(named: "notify")
        vc4.tabBarItem.selectedImage = UIImage(named: "notify_selected")?.withRenderingMode(.alwaysOriginal)

        
        
        // 通过 tabBar 的 tintColor 
        // 一步设置`选中状态`时的颜色
        //tintcolor只会影响选中颜色,不会影响`普通`状态时的颜色
        tabBarViewController.tabBar.tintColor = .green
        
        
        tabBarViewController.viewControllers = [vc1,vc2,vc3,vc4]
        
        if #available(iOS 13, *) {
            let vc5 = FifthVC()
            vc5.title = "trash"
            vc5.tabBarItem.image = UIImage(systemName: "trash")
            tabBarViewController.viewControllers?.append(vc5)
        }
        
        window?.rootViewController = tabBarViewController
        return true
    }

   


}

